package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Taxtype;
import com.restaurant.service.TaxtypeService;

public class TaxtypeServiceImpl implements TaxtypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Taxtype addOrModify( Taxtype objTaxtype ) {
       return ( Taxtype ) hibernateTemplate.merge( objTaxtype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Taxtype deleteRecord( Taxtype objTaxtype ) {
       hibernateTemplate.delete( objTaxtype );
       return objTaxtype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Taxtype modifyRecord( Taxtype objTaxtype ) {
       return ( Taxtype ) hibernateTemplate.merge( objTaxtype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Taxtype> loadAll() {
       return (List<Taxtype>)hibernateTemplate.findByNamedQuery( "Taxtype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Taxtype loadByPrimaryKey( Long primaryKey ) {
       return (Taxtype) hibernateTemplate.get( Taxtype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Taxtype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Taxtype> loadByHql(String query) {
       return ( List<Taxtype> ) hibernateTemplate.find( query );
   }
}